//
//  QuestionDetailView.m
//  jinnengExam
//
//  Created by mac on 2020/8/16.
//  Copyright © 2020 jznrj. All rights reserved.
//

#import "QuestionDetailView.h"

@implementation QuestionDetailView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        CustomMenuButton* preview = [[CustomMenuButton alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/2, 52)];
        preview.tag = 100;
        [preview setButtonInfo:@{@"title":@"上一题", @"icon":@"icon_preview",@"highlightIcon":@"icon_preview_pressed"}];
        [preview addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        self.previewButton = preview;
        [self addSubview:self.previewButton];
        
        CustomMenuButton* next = [[CustomMenuButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2, 0, [UIScreen mainScreen].bounds.size.width/2, 52)];
        next.tag = 101;
        [next setButtonInfo:@{@"title":@"下一题", @"icon":@"icon_next",@"highlightIcon":@"icon_next_pressed"}];
        [next addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        self.nextButton = next;
        [self addSubview:self.nextButton];

        
        self.userInteractionEnabled = YES;
    }
    return self;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */
- (void)buttonAction:(id)sender
{
    if (self.delegate == nil) {
        return;
    }
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
    if (tag == 100) { // 上一题
        [self.delegate onButtonAction:0];
    }
    else if (tag == 101) { // 下一题
        [self.delegate onButtonAction:1];
    }
}

@end
